package kr.pe.johnkim.app.mobile.rest.dao;

import kr.pe.johnkim.app.domain.MyHistoryItemEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 2. 18.
 */
public class MyHistoryItemEventDaoImpl extends SqlMapClientDaoSupport implements MyHistoryItemEventDao {
    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(MyHistoryItemEventDaoImpl.class);
    
    /**
     * 아이템 이벤트를 등록 한다.
     *
     * @param myHistoryItemEvent
     * @return
     */
    @Override
    public boolean registerItemEvent(MyHistoryItemEvent myHistoryItemEvent) {
        logger.info("registerItemEvent");

        boolean result = false;

        try {
            getSqlMapClientTemplate().insert("MYHISTORY_ITEM_EVENT.registerItemEvent", myHistoryItemEvent);
            result = true;
            logger.info("Success to register item event.");
        } catch (Exception e) {
            result = false;
            logger.error("Fail to register item event.");
        }

        return result;
    }

    /**
     * 아이템 이벤트 목록을 가져 온다.
     *
     * @param myHistoryItemEvent
     * @return
     */
    @Override
    public List<MyHistoryItemEvent> selectItemEventList(MyHistoryItemEvent myHistoryItemEvent) {
        logger.info("selectItemEventList");
        return this.getSqlMapClientTemplate().queryForList("MYHISTORY_ITEM_EVENT.selectItemEventList", myHistoryItemEvent);
    }

    /**
     * 아이템 이벤트를 수정 한다.
     *
     * @param myHistoryItemEvent
     * @return
     */
    @Override
    public boolean updateItemEvent(MyHistoryItemEvent myHistoryItemEvent) {
        logger.info("updateItemEvent");

        boolean result = false;

        try {
            getSqlMapClientTemplate().update("MYHISTORY_ITEM_EVENT.updateItemEvent", myHistoryItemEvent);
            result = true;
            logger.info("Success to update item event.");
        } catch (Exception e) {
            result = false;
            logger.error("Fail to update item event.");
        }

        return result;
    }

    /**
     * 아이템 이벤트를 비활성화 한다.
     *
     * @param myHistoryItemEvent
     * @return
     */
    @Override
    public boolean updateDeactivateItemEvent(MyHistoryItemEvent myHistoryItemEvent) {
        logger.info("updateDeactivateItemEvent");

        boolean result = false;

        try {
            getSqlMapClientTemplate().update("MYHISTORY_ITEM_EVENT.updateDeactivateItemEvent", myHistoryItemEvent);
            result = true;
            logger.info("Success to deactivate item event.");
        } catch (Exception e) {
            result = false;
            logger.error("Fail to deactivate item event.");
        }

        return result;
    }
}
